<?php
class import
{
	private $sp = null;
	private $err = '';
	public $path = '';
	public function open()
	{
		if($this->sp == null) 
		{
			$this->sp = new SplFileObject($this->path, 'rb');
		}
	}
	public function total()
	{
		$this->sp->seek(filesize($this->path));
		return $this->sp->key();
	}
	public function get($len = 0,$start = 1,$num = 1)
	{
		$len = $len ? $len : $this->total();		
		$data = array();
		$this->sp->seek($start);
		while ($len-- && !$this->sp->eof()) 
		{
			$data[] = $this->sp->fgetcsv();
			$fp = fopen('../data/cache/'.md5($num).'.cache','wb');
			fwrite($fp, "\xEF\xBB\xBF<?php\nreturn\n".iconv("gbk", "utf-8//IGNORE", var_export($data, true))."\n?>");
			fclose($fp);
			$this->sp->next();
		}
	}
}
?>